import java.util.ArrayList;
/**
 * A User has a first name, last name, gender, birth date, email and password
 * 
 * @author Mathieu Reymond & Jonathan Smet 
 * @version 03/05/11
 */
public class User
{
    private String userName;
    private String email;
    private String password;
    private int year;
    private int month;
    private int day;
    private boolean gender;
    private String firstName;
    private String lastName;
    private ArrayList<String> likeList = new ArrayList<String>();
    private Planning userPlanning = new Planning();

    /**
     * Makes a new user
     * 
     * @param userName The user's pseudonym
     * @param email The user's email
     * @param password The users's password
     * @param year The year when the user was born
     * @param month The month of the user's birthday
     * @param day The day of the user's birhtday
     * @param gender The user's gender : true if male, false if female
     * @param firstName The user's first name
     * @param lastNamme The user's last name
     */
    public User(String userName, String email, String password, int year, int month, int day, boolean gender, String firstName, String lastName)
    {
        this.userName = userName;
        this.email = email.toLowerCase();
        this.password = password;
        this.year = year;
        this.month = month;
        this.day = day;
        this.gender = gender;
        this.firstName = firstName;
        this.lastName = lastName;
    }
    
    /**
     * Let you change the user's password, you have to give the old password if you want to succesfully change the password
     * 
     * @param newPassword The user's new password
     * @param oldPassword The user's old password
     * 
     * @return True if the password was succesfully changed, false otherwise
     */
    public boolean changePassword(String newPassword, String oldPassword)
    {
        boolean returnValue = false;
        if(oldPassword.equals(password))
        {
            password = newPassword;
            returnValue = true;
        }
        return returnValue;
    }
    
    /**
     * Let the user like a particular performance. This method is also used to cancel a performance the user like (unlike the performance)
     * 
     * @param bandName The name of the performance the user wants to likes/unlikes
     */
    public void like(String performanceName)
    {
        int index = likeList.indexOf(performanceName);
        if(index >= 0)
        {
            likeList.remove(index);
            LineUp.getLineUp().get(performanceName).setLike(false);
        }
        else
        {
            likeList.add(performanceName);
            LineUp.getLineUp().get(performanceName).setLike(true);
        }
    }
    
    /**
     * Get the user's planning
     * 
     * @return The user's planning
     */
    public Planning getPlanning()
    {
        return userPlanning;
    }
    
    /**
     * Gives all kind of info : The user's first name, last name, pseudonym, birthday, age, gender, email
     * 
     * @return a String with all the information
     */
    public String showInfo()
    {
        String genderName = null;
        
        if(gender)
        {
            genderName = "Male";
        }
        else
        {
            genderName = "Female";
        }
        
        String info = firstName + " " + lastName + " ( " + genderName + " ) : \n\n" + "Email : " + email + "\n\nBorn on " + day + "/ " + month + "/ " + year + "\n\nLikes : ";
        
        int index = 0;
        while( index < likeList.size())
        {
            if(index > 0)
            {
                info += ", ";
            }
            
            info += likeList.get(index);
            index++;
        }
        
        if(index == 0)
        {
            info += "nothing.";
        }
        info += " \n\nIs attending: ";
        index =0;
        while (index < userPlanning.getPlanningList().size())
        {
            
            if ( index> 0)
            {
                info += ",";
            }
            info += userPlanning.getPlanningList().get(index);
            index++;
        }
          
        if(index == 0)
        {
            info += "nothing.";
        }
        
        return info;
    }
    
    /**
     * Get the user's password
     * 
     * @return The user's password
     */
    public String getPassword()
    {
        return password;
    }
    
    /**
     * Get the user's email
     * 
     * @return The user's email
     */
    public String getEmail()
    {
        return email;
    }
    
        /**
     * Get the name of the user
     * 
     * @return The name of the user
     */
    public String getName()
    {
        return userName;
    }
    
        /**
     * Gets the list of all the performances the user likes
     * 
     * @return the Arraylist of the performances the user likes
     */
    public ArrayList<String> getLikeList()
    {
        return likeList;
    }
    
        /**
     * Changes the e-mail of the users' account
     * 
     * @param newEmail The new e-mailadress of the user
     */
    public void setEmail(String newEmail)
    {
        email = newEmail.toLowerCase();
    }
  
}
